// 结构体引用说明
#include<iostream>
using namespace std;
// 定义结构体
struct free_throws
{
    std::string name;
    int made;
    int attempts;
    float percent;
};
// 只是为了显示结构体，声明const禁止修改元素，使用结构体的引用
// 为了更快的处理
void display(const free_throws &ft);
// 修改结构体的内容，不能声明为const
void set_pc(free_throws &ft);
free_throws & accumulate(free_throws & target,const free_throws &source);
int main()
{
	// 定义结构体变量并初始化
	free_throws one = {"name1",13,14};
	free_throws two = {"name2",10,16};
	free_throws three = {"name3",7,9};
	free_throws four = {"name4",5,9};
	free_throws five = {"name5",6,14};
	free_throws team = {"name6",0,0};
	// 定义结构体变量，不初始化
	free_throws dup;
	set_pc(one);
	display(one);
	accumulate(team,one);
	display(team);
	// 使用返回值作为参数
	display(accumulate(team,two));
	accumulate(accumulate(team,three),four);
	display(team);
	// 使用复制的返回值dup
	dup = accumulate(team,five);
	std::cout<<"display team:\n";
	display(team);
	std::cout<<"Displaying dup after assignment:\n";
	display(dup);
	set_pc(four);
	accumulate(dup,five) = four;
	std::cout<<"Displaying dup after ill-advised assignment:\n";
	display(dup);
	return 0;
}
void display(const free_throws & ft)
{
	using std::cout;
	cout<<"Name: "<<ft.name<<'\n';
	cout<<" Made: "<<ft.made<<'\t';
	cout<<"Attempts: "<<ft.attempts<<'\t';
	cout<<"Percent: "<<ft.percent<<'\n';
}
void set_pc(free_throws &ft)
{
    if(ft.attempts !=0)
    {
	    ft.percent = 100.0f*float(ft.made)/float(ft.attempts);
    }
    else
    {
	    ft.percent = 0;
    }
}
free_throws & accumulate(free_throws &target,const free_throws &source)
{
	target.attempts += source.attempts;
	target.made += source.made;
	set_pc(target);
	return target;
}
